?
<template>
  <nav class="navbar">
    <div class="nav-container">
      <div class="nav-brand">
        <router-link to="/" class="brand-link">
          <span class="brand-text">XappTool</span>
        </router-link>
      </div>
      
      <ul class="nav-menu">
        <li class="nav-item">
          <router-link to="/" class="nav-link">首页</router-link>
        </li>
        <li class="nav-item">
          <router-link to="/docs" class="nav-link">技术文档</router-link>
        </li>
        <li class="nav-item">
          <router-link to="/price" class="nav-link">服务价格</router-link>
        </li>
        <li class="nav-item">
          <a target="_blank" rel="noopener" class="nav-link" href="https://qm.qq.com/cgi-bin/qm/qr?k=87WUZpcFdX6yfRw_sAhnL1WASNY0UuQy&jump_from=webapi&authKey=W4C1daV8wd5nc9oDKEnLugsbwcsQEb/ebuKPBqQoAG6aJdqRIA3veXIcCSm6McV5"><img border="0" src="//pub.idqqimg.com/wpa/images/group.png" alt="XappTool开发者群" title="XappTool开发者群"></a>

        </li>
        
        <template v-if="userStore.isLoggedIn">
          <li class="nav-item">
            <router-link to="/console" class="nav-link">控制台</router-link>
          </li>
          <!-- 会员状态显示 -->
          <li class="nav-item membership-status" v-if="membershipInfo">
            <span class="membership-badge" :class="membershipClass">
              <i class="el-icon-crown"></i>
              {{ membershipInfo.plan_name }}
              <span v-if="membershipInfo.membership_status === 'expired'" class="expired-tag">已过期</span>
              <span v-else-if="isExpiringSoon" class="expiring-tag">即将到期</span>
            </span>
          </li>
          <li class="nav-item dropdown">
            <a href="#" class="nav-link dropdown-toggle" @click.prevent="toggleDropdown">
              我的账户
              <i class="el-icon-arrow-down"></i>
            </a>
            <div class="dropdown-menu" v-show="showDropdown">
              <router-link to="/console" class="dropdown-item">应用管理</router-link>
              <router-link to="/console/stats" class="dropdown-item">数据统计</router-link>
              <router-link to="/console/test" class="dropdown-item">开发测试</router-link>
              <div class="dropdown-divider"></div>
              <router-link to="/membership" class="dropdown-item">
                <i class="el-icon-crown"></i>
                {{ membershipInfo ? '会员中心' : '开通会员' }}
              </router-link>
              <router-link to="/billing" class="dropdown-item">
                <i class="el-icon-document"></i>
                我的账单
              </router-link>
              <div class="dropdown-divider"></div>
              <a href="#" class="dropdown-item" @click.prevent="handleLogout">退出登录</a>
            </div>
          </li>
        </template>
        <template v-else>
          <li class="nav-item">
            <router-link to="/login" class="nav-link">登录</router-link>
          </li>
          <li class="nav-item">
            <router-link to="/register" class="nav-link nav-link-primary">免费注册</router-link>
          </li>
        </template>
      </ul>
      
      <div class="nav-toggle" @click="toggleMobileMenu">
        <span></span>
        <span></span>
        <span></span>
      </div>
    </div>
  </nav>
</template>

<script>
import { useUserStore } from '@/stores/user'
import { useRouter } from 'vue-router'
import { ref, computed, onMounted } from 'vue'
import { getMembershipInfo } from '@/api/membership'

export default {
  setup() {
    const userStore = useUserStore()
    const router = useRouter()
    const showDropdown = ref(false)
    const showMobileMenu = ref(false)
    const membershipInfo = ref(null)

    // 计算会员样式类
    const membershipClass = computed(() => {
      if (!membershipInfo.value) return ''
      
      const status = membershipInfo.value.membership_status
      if (status === 'expired') return 'expired'
      if (isExpiringSoon.value) return 'expiring'
      
      const planType = membershipInfo.value.plan_type
      if (planType === 'basic') return 'basic'
      if (planType === 'premium') return 'premium'
      if (planType === 'enterprise') return 'enterprise'
      
      return ''
    })

    // 计算是否即将到期（7天内）
    const isExpiringSoon = computed(() => {
      if (!membershipInfo.value || membershipInfo.value.membership_status === 'expired') {
        return false
      }
      
      const endDate = new Date(membershipInfo.value.membership_end_date)
      const now = new Date()
      const diffTime = endDate - now
      const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24))
      
      return diffDays <= 7 && diffDays > 0
    })

    // 获取会员信息
    const loadMembershipInfo = async () => {
      if (!userStore.isLoggedIn) return
      
      try {
        const response = await getMembershipInfo()
        if (response.data.code === 200) {
          membershipInfo.value = response.data.data.limit_info
        }
      } catch (error) {
        console.error('获取会员信息失败:', error)
      }
    }

    const handleLogout = () => {
      userStore.logout()
      showDropdown.value = false
      membershipInfo.value = null
      router.push('/login')
    }

    const toggleDropdown = () => {
      showDropdown.value = !showDropdown.value
    }

    const toggleMobileMenu = () => {
      showMobileMenu.value = !showMobileMenu.value
    }

    // 点击外部关闭下拉菜单
    const closeDropdown = (event) => {
      if (!event.target.closest('.dropdown')) {
        showDropdown.value = false
      }
    }

    // 监听点击事件
    document.addEventListener('click', closeDropdown)

    // 组件挂载时加载会员信息
    onMounted(() => {
      loadMembershipInfo()
    })

    return {
      userStore,
      membershipInfo,
      membershipClass,
      isExpiringSoon,
      showDropdown,
      showMobileMenu,
      handleLogout,
      toggleDropdown,
      toggleMobileMenu
    }
  }
}
</script>

<style scoped>
.navbar {
  background: #ffffff;
  padding: 0;
  position: sticky;
  top: 0;
  z-index: 1000;
  border-bottom: 1px solid #e4e7ed;
}

.nav-container {
  width: 100%;
  margin: 0;
  padding: 0 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 70px;
}

.nav-brand {
  flex-shrink: 0;
}

.brand-link {
  text-decoration: none;
  color: #303133;
  font-size: 1.5rem;
  font-weight: bold;
}

.brand-text {
  background: linear-gradient(45deg, #fff, #f0f0f0);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.nav-menu {
  list-style: none;
  display: flex;
  align-items: center;
  margin: 0;
  padding: 0;
  gap: 2rem;
}

.nav-item {
  position: relative;
}

.nav-link {
  color: #303133;
  text-decoration: none;
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.nav-link:hover {
  background: #f8f9fa;
}

.nav-link.router-link-active {
  background: #eef2ff;
}

.nav-link-primary {
  background: #ff6b6b;
  color: white;
  padding: 0.75rem 1.5rem;
  border-radius: 2rem;
  font-weight: 500;
}

.nav-link-primary:hover {
  background: #ff5252;
  transform: translateY(-2px);
}

/* 下拉菜单 */
.dropdown-menu {
  position: absolute;
  top: 100%;
  right: 0;
  background: white;
  border-radius: 0.5rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  min-width: 180px;
  padding: 0.5rem 0;
  margin-top: 0.5rem;
  z-index: 1001;
}

.dropdown-item {
  display: block;
  padding: 0.75rem 1.5rem;
  color: #303133;
  text-decoration: none;
  transition: all 0.3s ease;
}

.dropdown-item:hover {
  background: #f8f9fa;
  color: #667eea;
}

.dropdown-divider {
  height: 1px;
  background: #e4e7ed;
  margin: 0.5rem 0;
}

.dropdown-toggle i {
  transition: transform 0.3s ease;
  font-size: 0.8rem;
}

.dropdown-toggle:hover i {
  transform: rotate(180deg);
}

/* 移动端菜单按钮 */
.nav-toggle {
  display: none;
  flex-direction: column;
  cursor: pointer;
  padding: 0.5rem;
}

.nav-toggle span {
  width: 25px;
  height: 3px;
  background: white;
  margin: 3px 0;
  transition: 0.3s;
  border-radius: 2px;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .nav-container {
    padding: 0 1rem;
  }
  
  .nav-menu {
    position: fixed;
    left: -100%;
    top: 70px;
    flex-direction: column;
    background: white;
    width: 100%;
    text-align: center;
    transition: 0.3s;
    box-shadow: 0 10px 27px rgba(0, 0, 0, 0.05);
    padding: 2rem 0;
    gap: 1rem;
  }
  
  .nav-menu.active {
    left: 0;
  }
  
  .nav-item {
    width: 100%;
  }
  
  .nav-link {
    color: #303133;
    justify-content: center;
    padding: 1rem;
    font-size: 1.1rem;
  }
  
  .nav-link:hover {
    background: #f8f9fa;
    color: #667eea;
  }
  
  .nav-link-primary {
    background: #667eea;
    color: white;
    margin: 0 2rem;
  }
  
  .nav-toggle {
    display: flex;
  }
  
  .dropdown-menu {
    position: static;
    box-shadow: none;
    border-radius: 0;
    background: #f8f9fa;
    margin: 0;
    width: 100%;
  }
  
  .dropdown-item {
    text-align: center;
    padding: 1rem;
  }
}

@media (max-width: 480px) {
  .nav-container {
    padding: 0 1rem;
  }
  
  .brand-text {
    font-size: 1.3rem;
  }
  
  .nav-menu {
    gap: 0.5rem;
  }
  
  .nav-link {
    padding: 0.75rem;
    font-size: 1rem;
  }
}

/* 会员状态显示 */
.membership-status {
  margin-right: 1rem;
}

.membership-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.5rem 1rem;
  border-radius: 2rem;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.3s ease;
}

.membership-badge i {
  margin-right: 0.5rem;
}

/* 基础版样式 */
.membership-badge.basic {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

/* 高级版样式 */
.membership-badge.premium {
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
  color: white;
}

/* 企业版样式 */
.membership-badge.enterprise {
  background: linear-gradient(135deg, #fa709a 0%, #fee140 100%);
  color: white;
}

/* 即将到期样式 */
.membership-badge.expiring {
  background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%);
  color: #e67e22;
  animation: pulse 2s infinite;
}

/* 已过期样式 */
.membership-badge.expired {
  background: #f5f7fa;
  color: #c0c4cc;
  border: 1px solid #e4e7ed;
}

/* 状态标签 */
.expired-tag,
.expiring-tag {
  margin-left: 0.5rem;
  padding: 0.25rem 0.5rem;
  border-radius: 0.25rem;
  font-size: 0.75rem;
  font-weight: 500;
}

.expired-tag {
  background: #fef0f0;
  color: #f56c6c;
}

.expiring-tag {
  background: #fdf6ec;
  color: #e6a23c;
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(255, 193, 7, 0.7);
  }
  70% {
    box-shadow: 0 0 0 10px rgba(255, 193, 7, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(255, 193, 7, 0);
  }
}

</style>